<template>
	<view class="chicken_box">
		<img src="https://oneredhealth.oss-cn-hangzhou.aliyuncs.com/2023/10/12/9547205957d245a38607e477684bc95c.png"
			alt="" />
		<view class="chicken_btn" @click="to_game()">跳转福鸡乐园</view>
	</view>
</template>

<script>
	import caches from "@/config/caches.js";
	import {
		chickUrl
	} from "@/config/tendIdConfig.js";
	import {
		encryption
	} from "@/utils/encryption.js";
	export default {
		data() {
			return {
				chick_trade_no: '1'
			};
		},
		onLoad(options) {
			this.chick_trade_no = options.orderNum;
			this.chick_num = options.productCount;
			this.phone = uni.getStorageSync(caches.PHONE);
			console.log(this.phone, "小鸡页面options", options);
			this.chickenGame()
		},
		methods: {
			to_game() {
				uni.redirectTo({
					url: `/pages_shop1/pay/chickenDetail/jump?url=${encodeURIComponent(
			        chickUrl + "/go"
			    )}&api_token=${this.token}`,
				});
				console.log(this.token, "11");
			},
			chickenGame() {
				wx.request({
					url: chickUrl + "/api/v1/auth/phone-login",
					method: "POST",
					data: {
						...encryption({
							user_phone: this.phone,
							chick_trade_no: this.chick_trade_no,
							chick_id: "1", //小鸡ID
							chick_num: this.chick_num, //小鸡数量
							scene: "11", //场景领小鸡
						}),
					},
					success: (res) => {
						this.token = res.data.data.token;
						this.url = chickUrl + "/go?api_token=" + this.token;
						console.log(this.url, "22222");
					},
					fail: (err) => {
						console.log(err, "22");
					},
				});
			},
		},
	};
</script>

<style lang="scss">
	.chicken_box {
		margin: 300rpx auto;
		text-align: center;

		img {
			width: 200rpx;
			height: 260rpx;
		}
	}

	.chicken_btn {
		width: 464rpx;
		height: 86rpx;
		background: #d8d8d8;
		border-radius: 20rpx;
		line-height: 86rpx;
		color: #333;
		font-size: 36rpx;
		margin: 60rpx auto;
	}
</style>
